﻿<Window x:Class="Pvp.App.View.SettingsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:app="clr-namespace:Pvp.App"
        xmlns:res="clr-namespace:Pvp.App.Resources"
        xmlns:util="clr-namespace:Pvp.App.Util"
        xmlns:view="clr-namespace:Pvp.App.View"
        xmlns:engine="clr-namespace:Pvp.Core.MediaEngine;assembly=Pvp.Core"
        xmlns:vm="clr-namespace:Pvp.App.ViewModel"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
        Title="{x:Static res:Resources.settings_caption}" Height="400" Width="600"
        DataContext="{x:Static app:ViewModelLocator.SettingsViewModel}"
        Loaded="window_Loaded"
        ResizeMode="NoResize"
        util:WindowCustomizer.ShowIcon="False">
    
    <Window.Resources>
        <view:RendererToBooleanValueConverter x:Key="RendererConverter" />
        <view:MouseWheelActionToBooleanConverter x:Key="MouseWheelActionToBooleanConverter" />
        <view:KeyCombinationTranslateConverter x:Key="KeyCombinationTranslateConverter" />
        <view:FileTypeTranslateConverter x:Key="FileTypeTranslateConverter" />
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <TabControl TabStripPlacement="Top" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <TabItem Header="{x:Static res:Resources.settings_general_caption}" DataContext="{Binding GeneralSettingsViewModel}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    
                    <GroupBox Grid.Row="0" Header="{x:Static res:Resources.settings_general_player_options}" Margin="5">
                        <StackPanel>
                            <CheckBox Content="{x:Static res:Resources.settings_general_start_fullscreen}" 
                                      IsChecked="{Binding StartFullScreen, Mode=TwoWay}" Margin="8,8,8,4" />
                            <CheckBox Content="{x:Static res:Resources.settings_general_autoplay}" 
                                      IsChecked="{Binding AutoPlay, Mode=TwoWay}" Margin="8,3,8,4" />
                            <CheckBox Content="{x:Static res:Resources.settings_general_remember_volume}" 
                                      IsChecked="{Binding RememberVolume, Mode=TwoWay}" Margin="8,3,8,4" />
                            <CheckBox Content="{x:Static res:Resources.settings_general_center_window}" 
                                      IsChecked="{Binding CenterWindow, Mode=TwoWay}" Margin="8,3,8,4" />
                            <CheckBox Content="{x:Static res:Resources.settings_general_show_logo}" 
                                      IsChecked="{Binding ShowLogo, Mode=TwoWay}" Margin="8,3,8,4" />
                            <CheckBox Content="{x:Static res:Resources.settings_general_topmost}" 
                                      IsChecked="{Binding TopMost, Mode=TwoWay}" Margin="8,3,8,6" />
                        </StackPanel>
                    </GroupBox>
                    <GroupBox Grid.Row="1" Header="{x:Static res:Resources.settings_general_screenshots_folder}" Margin="5">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBox Text="{Binding ScreenshotsFolder, Mode=TwoWay}" HorizontalAlignment="Stretch" Margin="5" />
                            <Button Command="{Binding ChooseFolderCommand}" Grid.Column="1" 
                                    Content="{x:Static res:Resources.settings_general_button_choose}"
                                    Margin="5" Padding="10,2,10,2"/>
                        </Grid>
                    </GroupBox>
                </Grid>
            </TabItem>
            
            <TabItem Header="{x:Static res:Resources.settings_video_caption}" DataContext="{Binding VideoSettingsViewModel}">
                <StackPanel>
                    <GroupBox Header="{x:Static res:Resources.settings_video_renderer}" Margin="5">
                        <StackPanel>
                            <RadioButton Content="{x:Static res:Resources.settings_video_vr}" 
                                      IsChecked="{Binding Renderer, Mode=TwoWay, Converter={StaticResource RendererConverter}, ConverterParameter='{x:Static engine:Renderer.VR}'}" Margin="8,8,8,4" />
                            <RadioButton Content="{x:Static res:Resources.settings_video_vmr}" 
                                      IsChecked="{Binding Renderer, Mode=TwoWay, Converter={StaticResource RendererConverter}, ConverterParameter='{x:Static engine:Renderer.VMR_Windowless}'}" Margin="8,3,8,4" />
                            <RadioButton Content="{x:Static res:Resources.settings_video_vmr_windowed}" 
                                      IsChecked="{Binding Renderer, Mode=TwoWay, Converter={StaticResource RendererConverter}, ConverterParameter='{x:Static engine:Renderer.VMR_Windowed}'}" Margin="8,3,8,4" />
                            <RadioButton Content="{x:Static res:Resources.settings_video_vmr9}" 
                                      IsChecked="{Binding Renderer, Mode=TwoWay, Converter={StaticResource RendererConverter}, ConverterParameter='{x:Static engine:Renderer.VMR9_Windowless}'}" Margin="8,3,8,4" />
                            <RadioButton Content="{x:Static res:Resources.settings_video_vmr9_windowed}" 
                                      IsChecked="{Binding Renderer, Mode=TwoWay, Converter={StaticResource RendererConverter}, ConverterParameter='{x:Static engine:Renderer.VMR9_Windowed}'}" Margin="8,3,8,4" />
                            <RadioButton Content="{x:Static res:Resources.settings_video_evr}" 
                                      IsChecked="{Binding Renderer, Mode=TwoWay, Converter={StaticResource RendererConverter}, ConverterParameter='{x:Static engine:Renderer.EVR}'}" Margin="8,3,8,6" />
                            <Button Content="{x:Static res:Resources.settings_video_recommended}" 
                                    Command="{Binding RecommendedRendererCommand}" 
                                    Margin="5" Padding="10,2,10,2" HorizontalAlignment="Right" />
                        </StackPanel>
                    </GroupBox>
                </StackPanel>
            </TabItem>

            <TabItem Header="{x:Static res:Resources.settings_keyboard_caption}" DataContext="{Binding KeyboardMouseSettingsViewModel}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <ListBox ItemsSource="{Binding Keys, Mode=OneWay}" Margin="5" HorizontalContentAlignment="Stretch">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Width="360" Text="{Binding Key, Converter={StaticResource KeyCombinationTranslateConverter}}" />
                                    <TextBlock Text="{Binding KeyCombination}" />
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="MouseDoubleClick">
                                <cmd:EventToCommand Command="{Binding EnterKeyCommand}" PassEventArgsToCommand="True" />
                            </i:EventTrigger>
                            <i:EventTrigger EventName="SelectionChanged">
                                <cmd:EventToCommand Command="{Binding SelectedItemChangedCommand}" PassEventArgsToCommand="True" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>
                    
                    <StackPanel Grid.Column="1">
                        <Button Content="{x:Static res:Resources.settings_keyboard_clear}" 
                                Command="{Binding ClearCommand}" Margin="5" Padding="10,2,10,2"/>
                        <Button Content="{x:Static res:Resources.settings_keyboard_clear_all}" 
                                Command="{Binding ClearAllCommand}" Margin="5" Padding="10,2,10,2"/>
                        <Button Content="{x:Static res:Resources.settings_keyboard_defaults}" 
                                Command="{Binding DefaultsCommand}" Margin="5" Padding="10,2,10,2"/>
                    </StackPanel>
                    
                    <GroupBox Grid.Row="1" Header="{x:Static res:Resources.settings_keyboard_mousewheel_action}" Margin="5">
                        <StackPanel>
                            <RadioButton  Content="{x:Static res:Resources.settings_mousewheel_action_volume}"
                                      IsChecked="{Binding MouseWheelAction, Mode=TwoWay, Converter={StaticResource MouseWheelActionToBooleanConverter}, ConverterParameter='{x:Static vm:MouseWheelAction.Volume}'}"
                                      Margin="8,8,8,4"/>
                            <RadioButton  Content="{x:Static res:Resources.settings_mousewheel_action_seek}"
                                      IsChecked="{Binding MouseWheelAction, Mode=TwoWay, Converter={StaticResource MouseWheelActionToBooleanConverter}, ConverterParameter='{x:Static vm:MouseWheelAction.Seek}'}"
                                      Margin="8,3,8,6"/>
                        </StackPanel>
                    </GroupBox>
                </Grid>
            </TabItem>

            <TabItem Header="{x:Static res:Resources.settings_filetypes_caption}" DataContext="{Binding FileTypesSettingsViewModel}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="{x:Static res:Resources.settings_filetypes_description}" Margin="5,5,5,10" TextWrapping="Wrap" />
                    
                    <ListBox Grid.Row="1" ItemsSource="{Binding Items, Mode=OneWay}" Margin="5,0,5,0">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <CheckBox Content="{Binding Extension, Converter={StaticResource FileTypeTranslateConverter}}"
                                              IsChecked="{Binding Selected, Mode=TwoWay}"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                    
                    <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
                        <Button Content="{x:Static res:Resources.settings_filetypes_select_all}" Padding="10,2,10,2" 
                                Margin="10,10,10,5" Command="{Binding SelectAllCommand}"/>
                        <Button Content="{x:Static res:Resources.settings_filetypes_clear_all}" Padding="10,2,10,2" 
                                Margin="10,10,10,5" Command="{Binding ClearAllCommand}"/>
                    </StackPanel>
                </Grid>
            </TabItem>
        </TabControl>
        
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
            <Button IsDefault="True" Content="{x:Static res:Resources.ok}" Command="{Binding OkCommand}" Margin="5" Padding="10,2,10,2" x:Name="_btnOk" />
            <Button IsCancel="True" Content="{x:Static res:Resources.cancel}" Command="{Binding CancelCommand}" Margin="5" Padding="10,2,10,2" x:Name="_btnCancel" />
            <Button Content="{x:Static res:Resources.apply}" Command="{Binding ApplyCommand}" Margin="5" Padding="10,2,10,2" x:Name="_btnApply" />
        </StackPanel>
    </Grid>
</Window>
